﻿
@{
    ViewBag.Title = "RichText";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style type="text/css">
    html, body {
        height: 100%;
        overflow: hidden;
        margin: 0px;
    }

    body {
        background: white;
        border: 1px solid #ddd;
        overflow: auto;
    }

    .toolbar {
        margin-top: 10px;
        text-align: center;
        height: 40px;
    }
</style>
<script type="text/javascript" src="~/js/jquery/ajaxfileupload.js"></script>
<script src="~/js/validate/jquery.validate.min.js"></script>
<script type="text/javascript" charset="utf-8" src="~/lib/UEditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="~/lib/UEditor/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="~/lib/UEditor/lang/zh-cn/zh-cn.js"></script>

<form id="form1" style="height:100%;width:100%;">
    <div style="width:100%; height:100%;margin-left:auto;margin-left:auto;">
        <table class="form" style="height:7%;">
            <tr>
                <th class="formTitle" style="width:5%;">标 题</th>
                <td class="formValue">
                    <input type="text" id="F_Title" name="F_Title" class="form-control required" style="width:95%;" />
                </td>
                <th class="formTitle" style="width:5%;"> 发布人 </th>
                <td class="formValue">
                    <input type="text" id="F_Spokesman" name="F_Spokesman" class="form-control required" style="width:95%;" value="@NFine.Code.OperatorProvider.Provider.GetCurrent().UserName" />
                </td>
                <th class="formTitle" style="width:5%">文章类型:</th>
                <td class="formValue">
                    <select id="F_Type" name="F_Type" class="form-control" style="width:88%;height:20px;"></select>
                </td>
            </tr>
        </table>
        <script id="editor" type="text/plain" style="width:99%;height:72%;margin-top:5px;margin-left:auto;margin-right:auto;">
        </script>
        <div class="toolbar">
            <div class="btn-group">
                <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" style="width:120px;" onclick="btn_save(true)"><i class="fa fa-plus"></i>发 布</a>

                <a id="NF-add" authorize="yes" class="btn btn-warning" style="width:120px;margin-left:20px;" onclick="btn_save(false)"><i class="fa fa-plus"></i>草 稿</a>
            </div>
        </div>
    </div>
    <input type="hidden" id="F_Content" name="F_Content" />
</form>
<script type="text/javascript">
    var keyValue = $.request("keyValue");




    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');

    function btn_save(status) {
        if (!$('#form1').formValid()) {
            return false;
        }
        $('#F_Content').val(UE.getEditor('editor').getContent());
        var form = $("#form1").formSerialize();
        form.F_Status = status;

        $.submitForm({
            url: "/SystemManage/RichText/SubmitForm?keyValue=" + keyValue,
            param: form,
            success: function (data) {
                if (data.state == "success") {
                    $.modalMsg(data.message, data.state);
                    setTimeout(function () {
                        $.currentTabClose();
                    }, 500);

                } else {
                    $.modalAlert(data.message, data.state);
                }
            }
        })
    }

    $(function () {

        $("#F_Type").bindSelect({
            url: "/SystemManage/ItemsData/GetListEnCode?enCode=NewsType",
            id: "F_ItemCode",
            text: "F_ItemName"
        });

        if (keyValue) {

            $.ajax({
                url: '/SystemManage/RichText/GetForm?keyValue=' + keyValue,
                type: 'get',
                dataType: 'json'
            }).then(function (data) {
                if (data) {
                    $('#F_Title').val(data.F_Title);
                    $('#F_Spokesman').val(data.F_Spokesman);
                    $('#F_Type').val(data.F_Type);
                    ue.ready(function () {
                        ue.setContent(data.F_Content);
                    });
                }
            });

        }
    });
</script>

